﻿
using Xacml.Core;
using Xacml.Core.Interfaces;
using System;
using System.Xml;

namespace Xacml.Core.Policy
{
  public class VariableReferenceElement : XacmlElement, IExpression
  {
    private string _variableId;

    public string VariableId
    {
      get
      {
        return this._variableId;
      }
    }

    public override bool IsReadOnly
    {
      get
      {
        return true;
      }
    }

    public VariableReferenceElement(XmlReader reader, XacmlVersion schemaVersion)
      : base(XacmlSchema.Policy, schemaVersion)
    {
      if (reader.LocalName == "VariableReference" && this.ValidateSchema(reader, schemaVersion))
        this._variableId = reader.GetAttribute("VariableId");
      else
        throw new Exception(Resource.ResourceManager[Resource.MessageKey.exc_invalid_node_name, new object[1]
        {
          (object) reader.LocalName
        }]);
    }

    public void WriteDocument(XmlWriter writer)
    {
      writer.WriteStartElement("VariableReference");
      writer.WriteAttributeString("VariableId", this._variableId);
      writer.WriteEndElement();
    }
  }
}
